from mainui.mainui import Ui_MainWindow
from relur import RulerWidget
from graphicview import GraphicsView
from PyQt5 import QtWidgets
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtWidgets import QAction
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QToolBar, \
    QGraphicsPolygonItem, QGraphicsLineItem, QGraphicsView, QGraphicsScene, QGraphicsRectItem, QComboBox, \
    QGraphicsEllipseItem,QScrollArea,QDialog,QLabel,QGraphicsDropShadowEffect,QTabWidget,QGroupBox,QDoubleSpinBox,QFrame,QCheckBox
from PyQt5.QtGui import QPainter, QPen, QBrush, QColor, QFont, QPolygonF
from PyQt5.QtCore import Qt, QRectF, QPointF, QLineF, QRect,QPoint
import sys
from functools import partial


class Ui_Main(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self):
        try:
            super(Ui_Main, self).__init__()
            self.setupUi(self)
            self.main_mh()
        except Exception as e:
            print(e)

    def main_mh(self):
        self.setWindowTitle('HWCNC MASTER')
        self.setWindowIcon(QIcon('./icon/file.png'))
        self.menu1.setIcon(QIcon('./icon/file.png'))
        self.pushButton.setIcon(QIcon('./icon/newfile.png'))  # 设置按钮图标
        self.pushButton.setIconSize(self.pushButton.size())  # 设置图标大小与按钮大小一致
        self.pushButton.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton.setToolTip("新建")
        self.pushButton_2.setIcon(QIcon('./icon/openfile.png'))  # 设置按钮图标
        self.pushButton_2.setIconSize(self.pushButton_2.size())  # 设置图标大小与按钮大小一致
        self.pushButton_2.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_2.setToolTip("打开")
        self.pushButton_3.setIcon(QIcon('./icon/savefile.png'))  # 设置按钮图标
        self.pushButton_3.setIconSize(self.pushButton_3.size())  # 设置图标大小与按钮大小一致
        self.pushButton_3.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_3.setToolTip("保存")
        self.pushButton_4.setIcon(QIcon('./icon/insertfile.png'))  # 设置按钮图标
        self.pushButton_4.setIconSize(self.pushButton_4.size())  # 设置图标大小与按钮大小一致
        self.pushButton_4.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_4.setToolTip("导入")
        self.pushButton_5.setIcon(QIcon('./icon/outputfile.png'))  # 设置按钮图标
        self.pushButton_5.setIconSize(self.pushButton_5.size())  # 设置图标大小与按钮大小一致
        self.pushButton_5.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_5.setToolTip("导出")
        self.pushButton_6.setIcon(QIcon('./icon/copyfile.png'))  # 设置按钮图标
        self.pushButton_6.setIconSize(self.pushButton_6.size())  # 设置图标大小与按钮大小一致
        self.pushButton_6.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_6.setToolTip("复制")
        self.pushButton_7.setIcon(QIcon('./icon/copyrefile.png'))  # 设置按钮图标
        self.pushButton_7.setIconSize(self.pushButton_7.size())  # 设置图标大小与按钮大小一致
        self.pushButton_7.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_7.setToolTip("粘贴")
        self.pushButton_8.setIcon(QIcon('./icon/deletefile.png'))  # 设置按钮图标
        self.pushButton_8.setIconSize(self.pushButton_8.size())  # 设置图标大小与按钮大小一致
        self.pushButton_8.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_8.setToolTip("删除")
        self.pushButton_9.setIcon(QIcon('./icon/backstep.png'))  # 设置按钮图标
        self.pushButton_9.setIconSize(self.pushButton_9.size())  # 设置图标大小与按钮大小一致
        self.pushButton_9.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_9.setToolTip("后退")
        self.pushButton_10.setIcon(QIcon('./icon/frontstep.png'))  # 设置按钮图标
        self.pushButton_10.setIconSize(self.pushButton_10.size())  # 设置图标大小与按钮大小一致
        self.pushButton_10.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_10.setToolTip("前进")
        self.pushButton_11.setIcon(QIcon('./icon/print.png'))  # 设置按钮图标
        self.pushButton_11.setIconSize(self.pushButton_11.size())  # 设置图标大小与按钮大小一致
        self.pushButton_11.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_11.setToolTip("打印")
        self.pushButton_12.setIcon(QIcon('./icon/cnc.png'))  # 设置按钮图标
        self.pushButton_12.setIconSize(self.pushButton_12.size())  # 设置图标大小与按钮大小一致
        self.pushButton_12.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_12.setToolTip("刻绘输出")
        self.pushButton_14.setIcon(QIcon('./icon/cncmanage.png'))  # 设置按钮图标
        self.pushButton_14.setIconSize(self.pushButton_14.size())  # 设置图标大小与按钮大小一致
        self.pushButton_14.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_14.setToolTip("切割管理")
        self.pushButton_13.setIcon(QIcon('./icon/cncmanage.png'))  # 设置按钮图标
        self.pushButton_13.setIconSize(self.pushButton_13.size())  # 设置图标大小与按钮大小一致
        self.pushButton_13.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_13.setToolTip("切割管理")
        self.pushButton_15.setIcon(QIcon('./icon/lkcnc.png'))  # 设置按钮图标
        self.pushButton_15.setIconSize(self.pushButton_15.size())  # 设置图标大小与按钮大小一致
        self.pushButton_15.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_15.setToolTip("轮廓切割")
        self.pushButton_16.setIcon(QIcon('./icon/keepilive.png'))  # 设置按钮图标
        self.pushButton_16.setIconSize(self.pushButton_16.size())  # 设置图标大小与按钮大小一致
        self.pushButton_16.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_16.setToolTip("激活/注销")
        self.pushButton_17.setIcon(QIcon('./icon/movie.png'))  # 设置按钮图标
        self.pushButton_17.setIconSize(self.pushButton_17.size())  # 设置图标大小与按钮大小一致
        self.pushButton_17.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_17.setToolTip("观看视频")
        self.pushButton_23.setIcon(QIcon('./icon/zongxiang.png'))  # 设置按钮图标
        self.pushButton_23.setIconSize(self.pushButton_23.size())  # 设置图标大小与按钮大小一致
        self.pushButton_23.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_24.setIcon(QIcon('./icon/hengxiang.png'))  # 设置按钮图标
        self.pushButton_24.setIconSize(self.pushButton_24.size())  # 设置图标大小与按钮大小一致
        self.pushButton_24.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_18.setIcon(QIcon('./icon/paperdirection.png'))  # 设置按钮图标
        self.pushButton_18.setIconSize(self.pushButton_18.size())  # 设置图标大小与按钮大小一致
        self.pushButton_18.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_19.setIcon(QIcon('./icon/setpage.png'))  # 设置按钮图标
        self.pushButton_19.setIconSize(self.pushButton_19.size())  # 设置图标大小与按钮大小一致
        self.pushButton_19.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_22.setIcon(QIcon('./icon/pageup.png'))  # 设置按钮图标
        self.pushButton_22.setIconSize(self.pushButton_22.size())  # 设置图标大小与按钮大小一致
        self.pushButton_22.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_21.setIcon(QIcon('./icon/pagedown.png'))  # 设置按钮图标
        self.pushButton_21.setIconSize(self.pushButton_21.size())  # 设置图标大小与按钮大小一致
        self.pushButton_21.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.pushButton_20.setIcon(QIcon('./icon/page1.png'))  # 设置按钮图标
        self.pushButton_20.setIconSize(self.pushButton_20.size())  # 设置图标大小与按钮大小一致
        self.pushButton_20.setStyleSheet("QPushButton { border: none; background: transparent; }")
        self.comboBox.setCurrentIndex(4)

        # 开始核入
        main_layout = QHBoxLayout(self.widget)

        # Left toolbar with buttons and shape selector
        left_toolbar = QToolBar("Tools", self.widget_2)
        self.addToolBar(Qt.BottomToolBarArea, left_toolbar)

        qss = """
                QPushButton { 
                    border: none; 
                    background: transparent; 
                }
                QPushButton:pressed { 
                    background-color: lightblue; 
                }
                QPushButton:!pressed {
                    background: transparent;
                }
                 QPushButton:checked {
                    background-color: lightblue;
                }
             """
        for i in range(6):
            button = QPushButton()
            button.clicked.connect(partial(self.huahuabutton_clicked, i + 1))
            if i == 0:
                button.setStyleSheet(qss)
                button.setIcon(QIcon('./icon/jiantou.png'))  # 设置按钮图标
                button.setIconSize(self.pushButton_18.size())  # 设置图标大小与按钮大小一致
            elif i == 1:
                button.setStyleSheet(qss)
                button.setIcon(QIcon('./icon/zhixian.png'))  # 设置按钮图标
                button.setIconSize(self.pushButton_18.size())  # 设置图标大小与按钮大小一致
            elif i == 2:
                button.setStyleSheet(qss)
                button.setIcon(QIcon('./icon/zfx.png'))  # 设置按钮图标
                button.setIconSize(self.pushButton_18.size())  # 设置图标大小与按钮大小一致
            elif i == 3:
                button.setStyleSheet(qss)
                button.setIcon(QIcon('./icon/ty.png'))  # 设置按钮图标
                button.setIconSize(self.pushButton_18.size())  # 设置图标大小与按钮大小一致
            elif i == 4:
                button.setStyleSheet(qss)
                button.setIcon(QIcon('./icon/hxzx.png'))  # 设置按钮图标
                button.setIconSize(self.pushButton_18.size())  # 设置图标大小与按钮大小一致
            elif i == 5:
                button.setStyleSheet(qss)
                button.setIcon(QIcon('./icon/T.png'))  # 设置按钮图标
                button.setIconSize(self.pushButton_18.size())  # 设置图标大小与按钮大小一致
            left_toolbar.addWidget(button)

            # Horizontal and vertical rulers
        self.h_ruler = RulerWidget(Qt.Horizontal)
        self.v_ruler = RulerWidget(Qt.Vertical)

        # Scene and view
        self.scene = QGraphicsScene()
        self.view = GraphicsView(self.h_ruler, self.v_ruler, self.scene)

        # A4 size drawing area
        a4_rect = QGraphicsRectItem(0, 0, 210, 297)
        a4_rect.setPen(QPen(Qt.black))
        a4_rect.setBrush(QBrush(QColor(173, 216, 230, 127)))  # Light blue color with transparency
        self.scene.addItem(a4_rect)

        # Layout for rulers and view
        rulers_layout = QVBoxLayout()
        rulers_layout.addWidget(self.h_ruler)
        rulers_layout.addWidget(self.view)
        main_layout.addWidget(self.v_ruler)
        main_layout.addLayout(rulers_layout)

        # Right fixed widget with buttons
        right_widget = QWidget()
        right_layout = QVBoxLayout(right_widget)
        for i in range(9):
            button = QPushButton()
            button.setMaximumSize(45, 45)
            if i == 0:
                button.setStyleSheet(qss)
                button.setIcon(QIcon('./icon/set.png'))  # 设置按钮图标
                button.setIconSize(self.pushButton_18.size())  # 设置图标大小与按钮大小一致
                self.button_1 = button
            elif i == 1:
                button.setStyleSheet(qss)
                button.setIcon(QIcon('./icon/zx.png'))  # 设置按钮图标
                button.setIconSize(self.pushButton_18.size())  # 设置图标大小与按钮大小一致
                self.button_2 = button
            elif i == 2:
                button.setStyleSheet(qss)
                button.setIcon(QIcon('./icon/xlj.png'))  # 设置按钮图标
                button.setIconSize(self.pushButton_18.size())  # 设置图标大小与按钮大小一致
                self.button_3 = button
            elif i == 3:
                button.setStyleSheet(qss)
                button.setIcon(QIcon('./icon/xl.png'))  # 设置按钮图标
                button.setIconSize(self.pushButton_18.size())  # 设置图标大小与按钮大小一致
            elif i == 4:
                button.setStyleSheet(qss)
                button.setIcon(QIcon('./icon/yxzfx.png'))  # 设置按钮图标
                button.setIconSize(self.pushButton_18.size())  # 设置图标大小与按钮大小一致
            elif i == 5:
                button.setStyleSheet(qss)
                button.setIcon(QIcon('./icon/xxsx.png'))  # 设置按钮图标
                button.setIconSize(self.pushButton_18.size())  # 设置图标大小与按钮大小一致
            elif i == 6:
                button.setStyleSheet(qss)
                button.setIcon(QIcon('./icon/yxwl.png'))  # 设置按钮图标
                button.setIconSize(self.pushButton_18.size())  # 设置图标大小与按钮大小一致
            elif i == 7:
                button.setStyleSheet(qss)
                button.setIcon(QIcon('./icon/lkzfx.png'))  # 设置按钮图标
                button.setIconSize(self.pushButton_18.size())  # 设置图标大小与按钮大小一致
            elif i == 8:
                button.setStyleSheet(qss)
                button.setIcon(QIcon('./icon/jgy.png'))  # 设置按钮图标
                button.setIconSize(self.pushButton_18.size())  # 设置图标大小与按钮大小一致
            button.clicked.connect(partial(self.youcebutton_clicked, i + 1))
            right_layout.addWidget(button)
        right_widget.setLayout(right_layout)
        main_layout.addWidget(right_widget)

        #颜色按钮
        # Create a scroll area
        scroll_area = QScrollArea()
        scroll_area.setWidgetResizable(True)
        # Create a container widget for the buttons
        container_widget = QWidget()
        container_layout = QHBoxLayout(container_widget)

        left_toolbar_2 = QToolBar("Tools", self.widget_2)
        self.addToolBar(Qt.BottomToolBarArea, left_toolbar_2)
        # Add buttons to the container
        for i in range(25):
            button = QPushButton(f"{i + 1}")
            button.clicked.connect(partial(self.colorbutton_clicked, i + 1))
            if i == 0:
                button.setStyleSheet(f"background-color: black;")
            elif i == 1:
                button.setStyleSheet(f"background-color: red;")
            elif i == 2:
                button.setStyleSheet(f"background-color: green;")
            elif i == 3:
                button.setStyleSheet(f"background-color: blue;")
            elif i == 4:
                button.setStyleSheet(f"background-color: cyan;")
            elif i == 5:
                button.setStyleSheet(f"background-color: magenta;")
            elif i == 6:
                button.setStyleSheet(f"background-color: yellow;")
            elif i == 7:
                button.setStyleSheet(f"background-color: gray;")
            elif i == 8:
                button.setStyleSheet(f"background-color: lightGray;")
            elif i == 9:
                button.setStyleSheet(f"background-color: darkGray;")
            elif i == 10:
                button.setStyleSheet(f"background-color: darkRed;")
            elif i == 11:
                button.setStyleSheet(f"background-color: darkGreen;")
            elif i == 12:
                button.setStyleSheet(f"background-color: darkBlue;")
            elif i == 13:
                button.setStyleSheet(f"background-color: darkCyan;")
            elif i == 14:
                button.setStyleSheet(f"background-color: darkMagenta;")
            elif i == 15:
                button.setStyleSheet(f"background-color: darkYellow;")
            elif i == 16:
                button.setStyleSheet(f"background-color: lightRed;")
            elif i == 17:
                button.setStyleSheet(f"background-color: lightGreen;")
            elif i == 18:
                button.setStyleSheet(f"background-color: lightBlue;")
            elif i == 19:
                button.setStyleSheet(f"background-color: lightCyan;")
            elif i == 20:
                button.setStyleSheet(f"background-color: lightMagenta;")
            elif i == 21:
                button.setStyleSheet(f"background-color: lightYellow;")

            container_layout.addWidget(button)

        container_widget.setLayout(container_layout)
        scroll_area.setWidget(container_widget)

        # Add the scroll area to the toolbar
        left_toolbar_2.addWidget(scroll_area)

        self.statusBar().showMessage("Mouse coordinates: (0, 0)")


    def mouseMoveEvent(self, event):
        scene_pos = self.view.mapToScene(self.view.mapFromParent(event.pos()))
        self.statusBar().showMessage(f"Mouse coordinates: ({scene_pos.x():.2f}, {scene_pos.y():.2f})")

    def changeShape(self, shape):
        self.view.setShape(shape)

    def changeColor(self, color):
        self.view.setColor(color)

    def youcebutton_clicked(self,button_number):
        try:
            if button_number == 1:
                self.show_popup()
        except Exception as e:
            print(e)

    #右侧第一个按钮
    def show_popup(self):
        button_position  = self.button_1.mapToGlobal(QPoint(0, 0))
        # 创建弹窗
        dialog = QDialog(self)
        dialog.setWindowFlags(Qt.FramelessWindowHint | Qt.Popup)  # 无边框、无标题栏
        dialog.setWindowTitle("")
        dialog.setFixedSize(200, 500)

        # 创建TabWidget并添加标签页
        tab_widget = QTabWidget(dialog)
        tab_widget.setGeometry(10, 10, 180, 450)  # 设置tab的大小
        tab_widget.setTabPosition(QTabWidget.East)  # 标签页竖向显示在右侧

        # 创建两个标签页
        tab1 = QWidget()
        tab2 = QWidget()
        tab3 = QWidget()
        tab4 = QWidget()
        tab5 = QWidget()

        # 为第一个标签页添加布局和内容
        # 创建一个QGroupBox放入tab1
        group_box = QGroupBox("位置/尺寸", tab1)
        group_box_layout = QVBoxLayout()

        # 创建一个水平布局，包含QLabel和QDoubleSpinBox
        hbox = QHBoxLayout()
        label = QLabel("左边距: ", group_box)
        spin_box = QDoubleSpinBox(group_box)
        spin_box.setRange(0.0, 100.0)  # 设置值范围
        spin_box.setDecimals(2)  # 设置小数点位数
        spin_box.setValue(0.0)  # 默认值
        # 将QLabel和QDoubleSpinBox添加到水平布局中
        hbox.addWidget(label)
        hbox.addWidget(spin_box)

        # 创建一个水平布局，包含QLabel和QDoubleSpinBox
        hbox_sbj = QHBoxLayout()
        label_sbj = QLabel("上边距: ", group_box)
        spin_box_sbj = QDoubleSpinBox(group_box)
        spin_box_sbj.setRange(0.0, 100.0)  # 设置值范围
        spin_box_sbj.setDecimals(2)  # 设置小数点位数
        spin_box_sbj.setValue(0.0)  # 默认值
        # 将QLabel和QDoubleSpinBox添加到水平布局中
        hbox_sbj.addWidget(label_sbj)
        hbox_sbj.addWidget(spin_box_sbj)

        # 添加一个QFrame作为水平分隔线
        line = QFrame()
        line.setFrameShape(QFrame.HLine)  # 设置为水平线
        line.setFrameShadow(QFrame.Sunken)  # 线的样式为凹陷

        # 创建一个水平布局，包含QLabel和QDoubleSpinBox
        hbox_kd = QHBoxLayout()
        label_kd = QLabel("宽度: ", group_box)
        spin_box_kd = QDoubleSpinBox(group_box)
        spin_box_kd.setRange(0.0, 100.0)  # 设置值范围
        spin_box_kd.setDecimals(2)  # 设置小数点位数
        spin_box_kd.setValue(0.0)  # 默认值
        # 将QLabel和QDoubleSpinBox添加到水平布局中
        hbox_kd.addWidget(label_kd)
        hbox_kd.addWidget(spin_box_kd)

        # 创建一个水平布局，包含QLabel和QDoubleSpinBox
        hbox_gd = QHBoxLayout()
        label_kd = QLabel("高度: ", group_box)
        spin_box_gd = QDoubleSpinBox(group_box)
        spin_box_gd.setRange(0.0, 100.0)  # 设置值范围
        spin_box_gd.setDecimals(2)  # 设置小数点位数
        spin_box_gd.setValue(0.0)  # 默认值
        # 将QLabel和QDoubleSpinBox添加到水平布局中
        hbox_gd.addWidget(label_kd)
        hbox_gd.addWidget(spin_box_gd)

        # 添加一个QFrame作为水平分隔线
        line_2 = QFrame()
        line_2.setFrameShape(QFrame.HLine)  # 设置为水平线
        line_2.setFrameShadow(QFrame.Sunken)  # 线的样式为凹陷

        # 添加QCheckBox
        checkbox = QCheckBox("比例锁", group_box)
        checkbox.setChecked(True)  # 默认选中

        # 创建一个水平布局，包含QLabel和QDoubleSpinBox
        hbox_sfx = QHBoxLayout()
        label_sfx = QLabel("缩放x", group_box)
        spin_box_sfx = QDoubleSpinBox(group_box)
        spin_box_sfx.setRange(0.0, 100.0)  # 设置值范围
        spin_box_sfx.setDecimals(2)  # 设置小数点位数
        spin_box_sfx.setValue(0.0)  # 默认值
        # 将QLabel和QDoubleSpinBox添加到水平布局中
        hbox_sfx.addWidget(label_sfx)
        hbox_sfx.addWidget(spin_box_sfx)

        # 创建一个水平布局，包含QLabel和QDoubleSpinBox
        hbox_sfy = QHBoxLayout()
        label_sfy = QLabel("缩放y", group_box)
        spin_box_sfy = QDoubleSpinBox(group_box)
        spin_box_sfy.setRange(0.0, 100.0)  # 设置值范围
        spin_box_sfy.setDecimals(2)  # 设置小数点位数
        spin_box_sfy.setValue(0.0)  # 默认值
        # 将QLabel和QDoubleSpinBox添加到水平布局中
        hbox_sfy.addWidget(label_sfy)
        hbox_sfy.addWidget(spin_box_sfy)

        # 将控件添加到GroupBox的布局
        #group_box_layout.addWidget(label)
        group_box_layout.addLayout(hbox)
        #group_box_layout.addWidget(label_sbj)
        group_box_layout.addLayout(hbox_sbj)
        group_box_layout.addWidget(line)
        #group_box_layout.addWidget(label_kd)
        group_box_layout.addLayout(hbox_kd)
        group_box_layout.addLayout(hbox_gd)
        #group_box_layout.addWidget(spin_box_gd)
        group_box_layout.addWidget(line_2)
        group_box_layout.addWidget(checkbox)

        #group_box_layout.addWidget(label_sfx)
        group_box_layout.addLayout(hbox_sfx)
        #group_box_layout.addWidget(label_sfy)
        group_box_layout.addLayout(hbox_sfy)
        group_box.setLayout(group_box_layout)


#___________________________________________________
        # 创建一个QGroupBox放入tab1
        group_box_2 = QGroupBox("旋转镜像", tab1)
        group_box_layout_2 = QVBoxLayout()
        #'''
        # 创建一个水平布局，包含QLabel和QDoubleSpinBox
        hbox_xzw = QHBoxLayout()
        label_xz = QLabel("旋转", group_box_2)
        spin_box_xz = QDoubleSpinBox(group_box_2)
        spin_box_xz.setRange(0.0, 100.0)  # 设置值范围
        spin_box_xz.setDecimals(2)  # 设置小数点位数
        spin_box_xz.setValue(0.0)  # 默认值
        label_xzd = QLabel("°", group_box_2)
        # 将QLabel和QDoubleSpinBox添加到水平布局中
        hbox_xzw.addWidget(label_xz)
        hbox_xzw.addWidget(spin_box_xz)
        hbox_xzw.addWidget(label_xzd)
        #'''
        # 创建一个水平布局，包含QLabel和QDoubleSpinBox
        hbox_qx = QHBoxLayout()
        label_qx = QLabel("倾斜", group_box_2)
        spin_box_qx = QDoubleSpinBox(group_box_2)
        spin_box_qx.setRange(0.0, 100.0)  # 设置值范围
        spin_box_qx.setDecimals(2)  # 设置小数点位数
        spin_box_qx.setValue(0.0)  # 默认值
        label_qxd = QLabel("mm", group_box_2)
        # 将QLabel和QDoubleSpinBox添加到水平布局中
        hbox_qx.addWidget(label_qx)
        hbox_qx.addWidget(spin_box_qx)
        hbox_qx.addWidget(label_qxd)

        # 创建一个水平布局，包含QLabel和QDoubleSpinBox
        hbox_butt = QHBoxLayout()
        button_zx = QPushButton("", group_box_2)
        button_zx.setIcon(QIcon('./icon/uppersh.png'))  # 设置按钮图标
        button_zx.setIconSize(button_zx.size())  # 设置图标大小与按钮大小一致
        button_sx = QPushButton("", group_box_2)
        button_sx.setIcon(QIcon('./icon/leftyo.png'))  # 设置按钮图标
        button_sx.setIconSize(button_zx.size())  # 设置图标大小与按钮大小一致
        # 将QLabel和QDoubleSpinBox添加到水平布局中
        hbox_butt.addWidget(button_zx)
        hbox_butt.addWidget(button_sx)

        #group_box_layout_2.addWidget(label_xz)
        #group_box_layout_2.addWidget(spin_box_xz)
        group_box_layout_2.addLayout(hbox_xzw)
        #group_box_layout_2.addWidget(label_qx)
        group_box_layout_2.addLayout(hbox_qx)
        group_box_layout_2.addLayout(hbox_butt)
        group_box_2.setLayout(group_box_layout_2)
#————————————————————————————————————————
        # 创建一个QGroupBox放入tab1
        group_box_3 = QGroupBox("对象属性", tab1)
        group_box_layout_3 = QVBoxLayout()

        # 创建一个水平布局，包含QLabel和QDoubleSpinBox
        hbox_dx = QHBoxLayout()
        label_dx = QLabel("缩放x", group_box_3)
        pixmap = QPixmap('./icon/threeheng.png')  # 使用图标的路径
        scaled_pixmap = pixmap.scaled(20, 20, Qt.KeepAspectRatio, Qt.SmoothTransformation)  # 调整图标大小
        label_dx.setPixmap(scaled_pixmap)  # 在 QLabel 中设置图标
        comboxm = QComboBox()
        # 将QLabel和QDoubleSpinBox添加到水平布局中
        hbox_dx.addWidget(label_dx)
        hbox_dx.addWidget(comboxm)

        # 添加QCheckBox
        checkbox_bkqgd = QCheckBox("不可切割的", group_box_3)
        checkbox_bkqgd.setChecked(0)  # 默认选中

        group_box_layout_3.addLayout(hbox_dx)
        group_box_layout_3.addWidget(checkbox_bkqgd)
        group_box_3.setLayout(group_box_layout_3)

        # 为tab1添加布局
        layout1 = QVBoxLayout()
        layout1.addWidget(group_box)  # 将GroupBox添加到tab1的布局
        layout1.addWidget(group_box_2)  # 将GroupBox添加到tab1的布局
        layout1.addWidget(group_box_3)  # 将GroupBox添加到tab1的布局

        tab1.setLayout(layout1)

        # 为第二个标签页添加布局和内容
        layout2 = QVBoxLayout()
        label2 = QLabel("步长和重复", tab2)
        layout2.addWidget(label2)
        tab2.setLayout(layout2)

        # 为第三个标签页添加布局和内容
        layout3 = QVBoxLayout()
        label3 = QLabel("排列", tab3)
        layout3.addWidget(label3)
        tab3.setLayout(layout3)

        # 为第四个标签页添加布局和内容
        layout4 = QVBoxLayout()
        label4 = QLabel("分布排列", tab4)
        layout4.addWidget(label4)
        tab4.setLayout(layout4)

        # 为第四个标签页添加布局和内容
        layout5 = QVBoxLayout()
        label5 = QLabel("分布排列", tab5)
        layout5.addWidget(label5)
        tab5.setLayout(layout5)

        # 添加标签页到TabWidget
        tab_widget.addTab(tab1, "对象变换")
        tab_widget.addTab(tab2, "步长和重复")
        tab_widget.addTab(tab3, "排列")
        tab_widget.addTab(tab4, "分布排列")
        tab_widget.addTab(tab5, "页面标记点")


        # 将弹窗的位置设定在按钮左边
        dialog.move(button_position.x() - dialog.width(), button_position.y())

        # 显示弹窗
        dialog.exec_()

    def colorbutton_clicked(self, button_number):
        try:
            if button_number == 1:
                self.changeColor(Qt.black)
            elif button_number == 2:
               self.changeColor(Qt.red)
        except Exception as e:
            print(e)
    def huahuabutton_clicked(self, button_number):
        try:
            if button_number == 1: #箭头
                self.changeShape('jiantou')
            elif button_number == 2: #直线
                self.changeShape('Line')
            elif button_number == 3: #正方形
                self.changeShape('Rectangle')
            elif button_number == 4: #椭圆
                self.changeShape('Ellipse')
            elif button_number == 5: #椭圆
                self.changeShape('Polygon')
            elif button_number == 6: #字
                self.changeShape('ziti')
        except Exception as e:
            print(e)

    # 运行窗口


if __name__ == "__main__":
    try:
        app = QtWidgets.QApplication(sys.argv)
        first = Ui_Main()
        first.show()
        sys.exit(app.exec_())
    except Exception as e:
        print(e)